package com.tj.test.sys.service.impl;

import com.tj.test.sys.dao.AnswerpaperMapper;
import com.tj.test.sys.po.Answerpaper;
import com.tj.test.sys.service.IAnswerpaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AnswerpaperService implements IAnswerpaperService {
    @Autowired
    private AnswerpaperMapper mapper;

    @Override
    //查询所有试卷答题表信息
    public List<Answerpaper> selectAllAnswerpaper() {
        List<Answerpaper> list=new ArrayList<>();
        if (!mapper.selectAllAnswerpaper().isEmpty()){
            list=mapper.selectAllAnswerpaper();
        }
        return list;
    }

    @Override
    //插入试卷答题表信息
    public int insertAnswerpaper(Answerpaper answerpaper) {
        int temp=0;
        /* 业务判断
         * （1）名称不能重复
         * （2）增加之前先查询*/
     /*   try{*/
            temp=mapper.selectAnswerpaperById(answerpaper);
            if (temp<1){
                temp=mapper.insertAnswerpaper(answerpaper);
            }else{
                return temp;
            }
  /*      }catch (Exception e){
            return -2;
        }*/
        return temp;
    }

    @Override
    //删除试卷答题表信息
    public int deleteAnswerpaper( Answerpaper answerpaper) {
        int temp=0;
        try{
            temp=mapper.selectAnswerpaperById(answerpaper);
            if (temp>0){
                temp=mapper.deleteAnswerpaper(answerpaper);
            }else{
                return -2;
            }
        }catch (Exception e){
            return -1;
        }
        return temp;
    }

    @Override
    //修改试卷答题表信息
    public int updateAnswerpaper(Answerpaper answerpaper) {
        int temp=0;
        try{
            temp=mapper.selectAnswerpaperById(answerpaper);
            if (temp<1){
                temp=mapper.updateAnswerpaper(answerpaper);
            }else{
                return temp;
            }
        }catch (Exception e){
            System.out.println(e.getStackTrace());
            return -1;
        }
        return temp;
    }
}
